home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / misc / MCPPReload.lha / MCPPReload / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-14  |  5.5 KB  |  270 lines

  1. #include <OSIncludes.h>
  2.  
  3. #pragma header
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. #include "misc.h"
  9.  
  10. /***************************************************/
  11.  
  12. static char *VERSTRING = "$VER: MCPPReload 0.5 (" __DATE2__ ")";
  13. static char *AUTHSTRING = "$AUTH: Georg Steger";
  14.  
  15. #define COMPILERFILE "bin/mcpp4"
  16. #define ARG_TEMPLATE "STACK/N/K,MUSTEXIST/S,QUIET/S"
  17.  
  18. enum {ARG_STACK,ARG_MUSTEXIST,ARG_QUIET,NUM_ARGS};
  19.  
  20. struct Library *RexxSysBase;
  21. struct IntuitionBase *IntuitionBase;
  22. struct GfxBase *GfxBase;
  23.  
  24. static struct RDArgs *MyArgs;
  25. static struct MsgPort *replyport;
  26. static struct RexxMsg *rexxmsg;
  27.  
  28. static LONG Args[NUM_ARGS];
  29. static BPTR lock,olddir,seglist;
  30. static BOOL resetcurrentdir;
  31.  
  32. static LONG stack = 10000;
  33.  
  34. static char *rexxcommand = "quit";
  35. static char *compilername = "MaxonCompiler";
  36. static char s[256];
  37.  
  38.  
  39. /***************************************************/
  40.  
  41. static void Cleanup(char *msg)
  42. {
  43.     WORD rc;
  44.  
  45.     if (msg)
  46.     {
  47.         printf("MCPPReload: %s\n",msg);
  48.         rc = RETURN_WARN;
  49.     } else {
  50.         rc = RETURN_OK;
  51.     }
  52.  
  53.     if (rexxmsg)
  54.     {
  55.         ClearRexxMsg(rexxmsg,1);
  56.         DeleteRexxMsg(rexxmsg);
  57.     }
  58.  
  59.     if (resetcurrentdir) CurrentDir(olddir);
  60.     if (lock) UnLock(lock);
  61.  
  62.     if (MyArgs) FreeArgs(MyArgs);
  63.  
  64.     if (replyport) DeleteMsgPort(replyport);
  65.     if (RexxSysBase) CloseLibrary(RexxSysBase);    
  66.  
  67.     exit(rc)
  68. }
  69.  
  70. static void OpenLibs(void)
  71. {
  72.     if (!(RexxSysBase = OpenLibrary("rexxsyslib.library",0)))
  73.     {
  74.         Cleanup("Can't open rexxsyslib.library!");
  75.     }
  76. }
  77.  
  78. static void GetArguments(void)
  79. {
  80.     if (!(MyArgs = ReadArgs(ARG_TEMPLATE,Args,0)))
  81.     {
  82.         Fault(IoErr(),0,s,255);
  83.         Cleanup(s);
  84.     }
  85.     
  86.     if (Args[ARG_STACK]) stack = *(LONG *)Args[ARG_STACK];
  87. }
  88.  
  89. static void Prepare(void)
  90. {
  91.     if (!(lock = Lock("MDEV:",ACCESS_READ)))
  92.     {
  93.         Cleanup("Can't lock \"MDEV:\"!");
  94.     }
  95.     
  96.     olddir = CurrentDir(lock);
  97.     resetcurrentdir = TRUE;
  98.  
  99.     if (!(replyport = CreateMsgPort()))
  100.     {
  101.         Cleanup("Can't create MsgPort!");
  102.     }
  103.  
  104.     if (!(rexxmsg = CreateRexxMsg(replyport,0,0)))
  105.     {
  106.         Cleanup("Can't create RexxMsg!");
  107.     }
  108.     
  109.     if (!(rexxmsg->rm_Args[0] = CreateArgstring(rexxcommand,strlen(rexxcommand))))
  110.     {
  111.         Cleanup("Out of memory!");
  112.     }
  113.     
  114.     rexxmsg->rm_Action = RXCOMM | RXFF_NOIO;
  115. }
  116.  
  117. static void KillCompiler(void)
  118. {
  119.     struct MsgPort *port;
  120.  
  121.     Forbid();
  122.     if ((port = FindPort("MAXONCPP")))
  123.     {
  124.         PutMsg(port,(struct Message *)rexxmsg);
  125.     }
  126.     Permit();
  127.     
  128.     if (port)
  129.     {
  130.         WaitPort(replyport);
  131.         GetMsg(replyport);
  132.     } else if (Args[ARG_MUSTEXIST]) {
  133.         Cleanup("ARexx port \"MAXONCPP\" not found. Compiler is not running!");
  134.     }
  135. }
  136.  
  137. static void RestartCompiler(void)
  138. {
  139.     BPTR homelock;
  140.  
  141.     Delay(50);
  142.  
  143.     if (!(seglist = NewLoadSeg(COMPILERFILE,0)))
  144.     {
  145.         Cleanup("Can't load compiler!");
  146.     }
  147.     
  148.     if (!(CreateNewProcTags(NP_Seglist,seglist,
  149.                                     NP_StackSize,stack,
  150.                                     NP_Arguments,"MAXONDEV.1",
  151.                                     NP_Cli,TRUE,
  152.                                     NP_CloseInput,TRUE,
  153.                                     NP_CloseOutput,TRUE,
  154.                                     NP_FreeSeglist,TRUE,
  155.                                     NP_CommandName,compilername,
  156.                                     NP_Name,compilername,
  157.                                     NP_HomeDir,homelock = DupLock(lock),
  158.                                     TAG_DONE)))
  159.     {
  160.         if (homelock) UnLock(homelock);
  161.         UnLoadSeg(seglist);
  162.         
  163.          Cleanup("Can't restart compiler!");
  164.     }
  165. }
  166.  
  167. static void ShowSuccess(void)
  168. {
  169.     static char *MESSAGE = "Compiler reloaded!";
  170.     static UWORD pattern[] = {0x5555,0xAAAA};
  171.     
  172.     struct Window *win;
  173.     struct Screen *scr;
  174.     struct DrawInfo *dri;
  175.     struct RastPort *rp,temprp;
  176.     WORD x,y,w,h,a,b;
  177.  
  178.     if (Args[ARG_QUIET]) return;
  179.  
  180.     if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",36)))
  181.     {
  182.         if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",36)))
  183.         {
  184.             scr = LockPubScreen("MaxonDevelop.1");
  185.             if (!scr) scr = LockPubScreen(0);
  186.             
  187.             if (scr)
  188.             {
  189.                 if ((dri = GetScreenDrawInfo(scr)))
  190.                 {
  191.                     InitRastPort(&temprp);
  192.                     SetFont(&temprp,dri->dri_Font);
  193.  
  194.                     x = TextLength(&temprp,MESSAGE,strlen(MESSAGE));
  195.                     y = dri->dri_Font->tf_YSize;
  196.                     
  197.                     w = x + 16 + 10;
  198.                     h = y + 8 + 10;
  199.                     
  200.                     CalcCenteredWin(scr,w,h,&a,&b);
  201.                     
  202.                     if ((win = OpenWindowTags(0,WA_PubScreen,scr,
  203.                                                          WA_Left,a,
  204.                                                          WA_Top,b,
  205.                                                          WA_Width,w+5,
  206.                                                          WA_Height,h+5,
  207.                                                          WA_Flags,WFLG_BORDERLESS|WFLG_SIMPLE_REFRESH,
  208.                                                          WA_BackFill,LAYERS_NOBACKFILL,
  209.                                                          TAG_DONE)))
  210.                     {
  211.                         rp = win->RPort;
  212.                         
  213.                         SetFont(rp,dri->dri_Font);
  214.                         SetDrMd(rp,JAM1);
  215.  
  216.                         SetAPen(rp,0);
  217.                         RectFill(rp,0,0,w-1,h-1);
  218.  
  219.                         SetAPen(rp,dri->dri_Pens[SHADOWPEN]);
  220.                         RectFill(rp,w-1,1,w-1,h-1);
  221.                         RectFill(rp,1,h-1,w-2,h-1);
  222.  
  223.                         RectFill(rp,5,5,w-6,h-6);
  224.  
  225.                         SetAfPt(rp,pattern,1);
  226.                         RectFill(rp,w,4,w+4,h-1);
  227.                         RectFill(rp,4,h,w+4,h+4);
  228.                         SetAfPt(rp,0,0);
  229.                         
  230.                         SetAPen(rp,dri->dri_Pens[SHINEPEN]);
  231.                         RectFill(rp,0,0,0,h-1);
  232.                         RectFill(rp,1,0,w-1,0);
  233.                         RectFill(rp,6,h-6,w-6,h-6);
  234.                         RectFill(rp,w-6,6,w-6,h-7);
  235.                         
  236.                         
  237.                         SetAPen(rp,dri->dri_Pens[SHINEPEN]);
  238.  
  239.                         Move(rp,(w - x) / 2,(h - y) / 2 + dri->dri_Font->tf_Baseline);
  240.                         Text(rp,MESSAGE,strlen(MESSAGE));
  241.  
  242.                         Delay(50*2);
  243.                         
  244.                         CloseWindow(win);
  245.                     } /* if ((win = ... */
  246.                     
  247.                     FreeScreenDrawInfo(scr,dri);
  248.                 } /* if ((dri = GetScreenDrawInfo(scr))) */
  249.                 
  250.                 UnlockPubScreen(0,scr);
  251.             } /* if (scr) */
  252.  
  253.             CloseLibrary((struct Library *)GfxBase);
  254.         } /* if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",36))) */
  255.  
  256.         CloseLibrary((struct Library *)IntuitionBase);
  257.     } /* if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",36))) */
  258. }
  259.  
  260. void main(void)
  261. {
  262.     OpenLibs();
  263.     GetArguments();
  264.     Prepare();
  265.     KillCompiler();
  266.     RestartCompiler();
  267.     ShowSuccess();
  268.     Cleanup(0);
  269. }    
  270.